package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordPhoto;
import com.letian.record.service.IRecordPhotoService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录照片Controller
 * 
 * @author bmz
 * @date 2023-11-06
 */
@RestController
@RequestMapping("/record/photo")
public class RecordPhotoController extends BaseController
{
    @Autowired
    private IRecordPhotoService recordPhotoService;

    /**
     * 查询记录照片列表
     */
    @PreAuthorize("@ss.hasPermi('record:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordPhoto recordPhoto)
    {
        startPage();
        List<RecordPhoto> list = recordPhotoService.selectRecordPhotoList(recordPhoto);
        return getDataTable(list);
    }

    /**
     * 查询记录照片列表
     */
    @PreAuthorize("@ss.hasPermi('record:photo:list')")
    @GetMapping("/my/list")
    public TableDataInfo myList(RecordPhoto recordPhoto)
    {
        startPage();
        recordPhoto.setCreateBy(getUsername());
        List<RecordPhoto> list = recordPhotoService.selectRecordPhotoList(recordPhoto);
        return getDataTable(list);
    }

    /**
     * 导出记录照片列表
     */
    @PreAuthorize("@ss.hasPermi('record:photo:export')")
    @Log(title = "记录照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordPhoto recordPhoto)
    {
        List<RecordPhoto> list = recordPhotoService.selectRecordPhotoList(recordPhoto);
        ExcelUtil<RecordPhoto> util = new ExcelUtil<RecordPhoto>(RecordPhoto.class);
        util.exportExcel(response, list, "记录照片数据");
    }

    /**
     * 获取记录照片详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:photo:query')")
    @GetMapping(value = "/{photoId}")
    public AjaxResult getInfo(@PathVariable("photoId") Long photoId)
    {
        return success(recordPhotoService.selectRecordPhotoByPhotoId(photoId));
    }

    /**
     * 新增记录照片
     */
    @PreAuthorize("@ss.hasPermi('record:photo:add')")
    @Log(title = "记录照片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordPhoto recordPhoto)
    {
        recordPhoto.setCreateBy(getUsername());
        return toAjax(recordPhotoService.insertRecordPhoto(recordPhoto));
    }

    /**
     * 修改记录照片
     */
    @PreAuthorize("@ss.hasPermi('record:photo:edit')")
    @Log(title = "记录照片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordPhoto recordPhoto)
    {
        recordPhoto.setUpdateBy(getUsername());
        Long count =recordPhoto.getUpdateCount() == null ? 1 : recordPhoto.getUpdateCount() + 1;
        recordPhoto.setUpdateCount(count);
        return toAjax(recordPhotoService.updateRecordPhoto(recordPhoto));
    }

    /**
     * 删除记录照片
     */
    @PreAuthorize("@ss.hasPermi('record:photo:remove')")
    @Log(title = "记录照片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{photoIds}")
    public AjaxResult remove(@PathVariable Long[] photoIds)
    {
        return toAjax(recordPhotoService.deleteRecordPhotoByPhotoIds(photoIds));
    }
}
